package com.bzxgc.sgwer.common.util;

import com.fasterxml.jackson.annotation.JsonInclude;

/**
 * json返回结果
 * 200：表示成功
 * 500：表示错误，错误信息在msg字段中
 */
public class JsonResult {
    private Integer status;
    private String msg;
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private Object data;

    public JsonResult() {
    }

    public JsonResult(Integer status, String msg, Object data) {
        this.status = status;
        this.msg = msg;
        this.data = data;
    }

    public static JsonResult success() {
        return new JsonResult(200, "操作成功", null);
    }

    public static JsonResult success(Object data) {
        return new JsonResult(200, "操作成功", data);
    }

    public static JsonResult success(String msg) {
        return new JsonResult(200, msg, null);
    }

    public static JsonResult success(String msg, Object data) {
        return new JsonResult(200, msg, data);
    }

    public static JsonResult error() {
        return new JsonResult(500, "操作失败", null);
    }

    public static JsonResult error(Object data) {
        return new JsonResult(500, "操作失败", data);
    }

    public static JsonResult error(String msg) {
        return new JsonResult(500, msg, null);
    }

    public static JsonResult error(String msg, Object data) {
        return new JsonResult(500, msg, data);
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "JsonResult{" +
                "status=" + status +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }
}
